package com.zz.servlet;

import com.zz.mapper.BookMapper;
import com.zz.model.Book;
import com.zz.mybatis.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * Created by Administrator on 2017/1/11.
 */
@WebServlet("/show.do")
public class show extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        SqlSession s = MybatisUtil.getSession();
        BookMapper bm = s.getMapper(BookMapper.class);
        if (req.getParameter("id") != null) {
            int idd = Integer.parseInt(req.getParameter("id").toString());
            System.out.println(idd);
            bm.deletee(idd);
            s.commit();
        }

        List<Book> lb = bm.query();
        req.setAttribute("book", lb);
        req.getRequestDispatcher("show.jsp").forward(req, resp);


    }
}
